package com.example.springbootredisdemo.controller;

import com.alibaba.fastjson.JSON;
import com.example.springbootredisdemo.dto.UserDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author sharloon
 * @date 2023/6/26
 */
@RestController
public class TestController {

    @Autowired
    private RedisTemplate redisTemplate;

    @GetMapping("/test")
    public String test() {
        redisTemplate.setValueSerializer(RedisSerializer.string());
        UserDTO userDTO = new UserDTO("sharloon", 18, 1);
        redisTemplate.convertAndSend("topic_1", JSON.toJSONString(userDTO));

        return "test ok";
    }
}
